package com.geetour.columbus.region.bo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.geetour.columbus.common.exceptions.BOException;
import com.geetour.columbus.common.model.R.ProvincePage;
import com.geetour.columbus.region.bo.IProvincePageBO;
import com.geetour.columbus.region.dao.IProvincePageDAO;

@Service
public class ProvincePageBOImpl implements IProvincePageBO {

    private IProvincePageDAO provincePageDAOImpl;

    @Autowired
    public void setProvincePageDAOImpl(IProvincePageDAO provincePageDAOImpl) {
        this.provincePageDAOImpl = provincePageDAOImpl;
    }

    @Override
    public void insertProvincePage(ProvincePage province) throws BOException {
        if (province == null || province.getName() == null) {
            return;
        }
        provincePageDAOImpl.insertProvincePage(province);
    }

    @Override
    public int insertProvincePageBatch(List<ProvincePage> list) throws BOException {
        if (list == null || list.isEmpty()) {
            return -1;
        }
        return provincePageDAOImpl.insertProvincePageBatch(list);
    }

    @Override
    public int updateProvincePage(ProvincePage province) throws BOException {
        if (province == null) {
            return -1;
        }
        return provincePageDAOImpl.updateProvincePageById(province);
    }

    @Override
    public int deleteProvincePage(Long id) throws BOException {
        if (id == null) {
            return -1;
        }
        return provincePageDAOImpl.deleteProvincePageById(id);
    }

    @Override
    public ProvincePage findProvincePageById(Long id) throws BOException {
        if (id == null) {
            return null;
        }
        return provincePageDAOImpl.findProvincePageById(id);
    }
    
    @Override
    public ProvincePage findProvincePageByName(String name) throws BOException {
        if (name == null) {
            return null;
        }
        ProvincePage param = new ProvincePage();
        param.setName(name);
        List<ProvincePage> provList = provincePageDAOImpl.findProvincePages(param);
        if (provList == null || provList.isEmpty()) {
            return null;
        }
        return provList.get(0);
    }


    @Override
    public List<ProvincePage> findAllProvincePages() throws BOException {
        return provincePageDAOImpl.findAllProvincePages();
    }

    @Override
    public List<ProvincePage> findProvincePages(ProvincePage province) throws BOException {
        if (province == null) {
            return null;
        }
        return provincePageDAOImpl.findProvincePages(province);
    }
    
}
